<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CResource extends CI_Controller {
	
	 public function __construct()
	    {
	        parent::__construct();
	        session_start();
	        //$this->output->enable_profiler(FALSE);
	   		if (!isset($_SESSION['uid']) || $_SESSION['uid'] < 1){
		    	redirect('cmemberlogin/requiredmessage','refresh');
		    }
		    else {
		    	if ($_SESSION['role_id'] !=3){
		    		redirect('cmemberlogin/restriction','refresh');
		    	}
		    }
	    }
	    
	public function index()
	{
		$data['title'] = "Resource Management";
		$data['left'] = 'site/lecturer_left';
		$data['main'] = 'site/resourcelist';
		$data['resources'] = $this->MResource->getAllResources();
		$this->load->vars($data);
		$this->load->view('site/template'); 
	}
	function create(){
	   	if ($this->input->post('file_type_id')){
	  		$this->MResource->addResource();
	  		$this->session->set_flashdata('message','Resource created');
	  		redirect('cresource','refresh');
	  	}else{
			$data['title'] = "Create Resource";
			$data['left'] = 'site/lecturer_left';
			$data['filetypes'] = $this->MResource->getFileType();
			$data['shifts'] = $this->MShift->getShiftDropDown();
			$data['courses'] = $this->MCourse->getCourseByUID($_SESSION['uid']);
			$data['main'] = 'site/resource_create';
			$this->load->vars($data);
			$this->load->view('site/template');    
		} 
	  }
  
	  function edit($id=0){
	  	if ($this->input->post('submit')){
	  		$this->MResource->updateResource();
	  		$this->session->set_flashdata('message','Resource updated');
	  		redirect('cresource','refresh');
	  	}else{
			$data['title'] = "Edit Resource";
			$data['left'] = 'site/lecturer_left';
			$data['main'] = 'site/resource_edit';
			$data['filetypes'] = $this->MResource->getFileType();
			$data['shifts'] = $this->MShift->getShiftDropDown();
			$data['courses'] = $this->MCourse->getCourseByUID($_SESSION['uid']);
			$data['resource'] = $this->MResource->getResource($id);
			if (!count($data['resource'])){
				redirect('cresource','refresh');
			}
			$this->load->vars($data);
			$this->load->view('site/template');      
		}
	  }
	  
	  function delete($id){
		//$id = $this->uri->segment(4);
		$this->MResource->deleteResource($id);
		$this->session->set_flashdata('message','Resource deleted');
		redirect('cresource','refresh');
	  }
	
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */